﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using InstrumentCheck.Module;
using InstrumentCheck.SQLHelper;

namespace InstrumentCheck.DAL
{
    public class Setting_dal
    {
        public Setting_dal()
        { }

        public List<ModuleProgram> GetAllMenu()
        {
            string sql = "select distinct ModuleNO,ModuleName,ISNULL(parentNO,0) ParentNO,";
            sql += " ISNULL(SortNO,0) SortNO,ISNULL(ModuleURL,'') ModuleURL from tbl_module order by moduleNO,ParentNO,SortNO";
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter();
            SQLHelper.SQLHelper.Fill(da, ds, sql, CommandType.Text, null);

            List<ModuleProgram> list = new List<ModuleProgram>();
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                ModuleProgram module = new ModuleProgram();
                module.ModuleNO = int.Parse(row["ModuleNO"].ToString());
                module.ModuleName = row["ModuleName"].ToString();
                module.ParentNO = int.Parse(row["ParentNO"].ToString());
                module.SortNO = int.Parse(row["SortNO"].ToString());
                module.ModuleURL = row["ModuleURL"].ToString();
                list.Add(module);
            }
            return list;
        }
    }
}
